package com.cccyy.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.regex.Pattern;

public class PwdUtil {
    private static final Logger log = LoggerFactory.getLogger(PwdUtil.class);

    /**
     * 校验是否包含大写字母
     */
    private static boolean hasUpperCase(String pwd) {
        String regex = ".*[A-Z].*";
        return Pattern.matches(regex, pwd);
    }

    /**
     * 校验是否包含小写字母
     */
    private static boolean hasLowCase(String pwd) {
        String regex = ".*[a-z].*";
        return Pattern.matches(regex, pwd);
    }

    /**
     * 校验是否包含数字
     */
    private static boolean hasNum(String pwd) {
        String regex = ".*\\d.*";
        return Pattern.matches(regex, pwd);
    }

    /**
     * 校验是否包含特殊字符
     */
    private static boolean hasSpecialCharacter(String pwd) {
        String regex = ".*[[_`~!@#$%^&()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：“”'。，、？]\\n|\\r|\\t].*";
        return Pattern.matches(regex, pwd);
    }

    public static void main(String[] args) {
        String pwd = "ABab1234";
        boolean b = hasSpecialCharacter(pwd);
        if (!b) {
            log.info("不包含特殊字符，应提示用户设置密码时需包含特殊字符");
        }
    }
}
